/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.controller.PengendaliPeriksaSuratDokument;
import com.util.FormUtil;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import model.Dosen;
import model.User;

/**
 *
 * @author Adell
 */
public class FormTambahDosen extends JDialog {

    private JLabel nama, nip, alamat;
    private JTextField teksnama, teksnip, teksalamat;
    private JButton tambah;

    public FormTambahDosen() {
        this.setSize(300, 300);
        FormUtil.centerWindow(this);
        this.setLayout(null);
        this.setVisible(true);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        this.setTitle(" Form DOSEN ");

        nama = new JLabel(" Nama ");
        nama.setBounds(10, 10, 100, 20);
        nama.setVisible(true);
        this.add(nama);


        nip = new JLabel(" NIP ");
        nip.setBounds(10, 40, 100, 20);
        nip.setVisible(true);
        this.add(nip);

        nip = new JLabel(" ALAMAT ");
        nip.setBounds(10, 70, 100, 20);
        nip.setVisible(true);
        this.add(nip);

        teksnama = new JTextField();
        teksnama.setBounds(120, 10, 100, 20);
        this.add(teksnama);

        teksnip = new JTextField();
        teksnip.setBounds(120, 40, 100, 20);
        this.add(teksnip);

        teksalamat = new JTextField();
        teksalamat.setBounds(120, 70, 100, 20);
        this.add(teksalamat);

        tambah = new JButton("OK");
        tambah.setBounds(100, 120, 100, 50);
        this.add(tambah);

        tambah.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                tambahAction();
                if (e.getSource() == tambah) {
                    dispose();
                }
            }

            private void tambahAction() {
                String nama = teksnama.getText();
                String nip = teksnip.getText();
                String alamat = teksalamat.getText();

                Dosen dsn = new Dosen();
                dsn.setNama(nama);
                dsn.setNIP(nip);
                dsn.setAlamat(alamat);
                PengendaliPeriksaSuratDokument.tambahDosen(dsn);
                try {
                    PengendaliPeriksaSuratDokument.tambahtableDosen(dsn);
                } catch (SQLException ex) {
                    Logger.getLogger(FormTambahDosen.class.getName()).log(Level.SEVERE, null, ex);
                }
                try {
                    PengendaliPeriksaSuratDokument.simpanTabelDosen();
                } catch (SQLException ex) {
                    Logger.getLogger(FormTambahDosen.class.getName()).log(Level.SEVERE, null, ex);
                }
                JOptionPane.showMessageDialog(null, " DATA TERSIMPAN ");
            }
        });
    }
}
